package com.wisdytech.linkdcs.pda.service.impl;


import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wisdytech.common.constants.CommonConstants;
import com.wisdytech.linkdcs.common.exception.ServiceException;
import com.wisdytech.linkdcs.common.handler.BaseService;
import com.wisdytech.linkdcs.equipment.dao.IEqEquipmentDao;
import com.wisdytech.linkdcs.equipment.model.Equipment;
import com.wisdytech.linkdcs.pda.service.ISystemService;
import com.wisdytech.linkdcs.system.dao.ISysUserDao;
import com.wisdytech.linkdcs.system.model.SysUser;

@Service("systemUserService")
@Transactional
public class SystemServiceImpl extends BaseService<ISysUserDao, SysUser> implements ISystemService {

	@Resource
	ISysUserDao systemUserDao;
	
	@Resource
	private IEqEquipmentDao equipDao;
	
	public boolean login(String username, String password) {
		EntityWrapper<SysUser> ew = new EntityWrapper<>();
		List<SysUser> users =
				systemUserDao.selectList(ew.eq("username", username).eq("del_flag", CommonConstants.DEL_FLAG));
		
		if(null == users || users.size()<1) {
			throw new ServiceException("账户不存在");
		}
		
		if(!users.get(0).getPassword().equals(password)) {
			throw new ServiceException("密码错误");
		}
		
		
		return true;
	}

	public List<String> getUserResource(String username) {
		//TODO 暂时未定，假数据
		List<String> resources =new ArrayList<>();
		resources.add("equipCheck.pda");
		resources.add("malfunctionRegister.pda");
		resources.add("malfunctionProcess.pda");
		resources.add("feeding.pda");
		resources.add("generateWIP.pda");
		resources.add("dust.pda");
		resources.add("messegeCenter.pda");
		resources.add("quException.pda");
		
		return resources;
	}

	@Override
	public List<SysUser> getUsers() {
		EntityWrapper<SysUser> ew = new EntityWrapper<>();
		return systemUserDao.selectList(ew.eq("del_flag", CommonConstants.DEL_FLAG));
		
	}

	@Override
	public Equipment getEquipDetail(String equipCode) {
		return equipDao.selectByEquipCode(equipCode);
	}

	
	
}
